package hr.eon.core;

import hr.eon.core.Constants.Messages;
import java.io.Serializable;

/**
 * Abstract class that all messages extends to become Eon message.
 * 
 * @author mjovanovic
 * @since 0.0.1
 */
public abstract class EonMessage implements Serializable, Cloneable {

    private static final long serialVersionUID = 6865597114070039268L;

    private int messageId;
    private String name;
    private Class<?> clazz;

    public EonMessage( Messages messageType, Class<?> clazz ) {
        this.messageId = messageType.getCode();
        this.name = clazz.getSimpleName();
        this.clazz = clazz;
    }

    public int getId() {
        return messageId;
    }

    public void setId( int id ) {
        this.messageId = id;
    }

    public String getName() {
        return name;
    }

    public void setName( String name ) {
        this.name = name;
    }

    public Class<?> getClazz() {
        return this.clazz;
    }

    @Override
    public String toString() {
        return String.format( "[%d:%s]", this.messageId, this.name );
    }

    @SuppressWarnings( "unchecked" )
    public <C> C doClone() throws CloneNotSupportedException {
        return (C) this.clone();
    }

}
